import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Button, Steps, Icon, Menu, Dropdown, Progress, Tooltip } from 'antd';
import styles from '../Users.css';
import Factory from '../../factory';
import dataEditCreate from '../../addons/DataEdit'
import dataTableCreate from '../../addons/DataTable'
import dataImportCreate from '../../addons/DataImport'
import * as datetime from '../../../utils/datetime'
const daoName = "IndiClieDiviFlowXJK";
const ButtonGroup = Button.Group;
const renderStep = (data) => {
    const { progress, status } = data
    const percent = Math.round(progress)
    return <Progress percent={percent} size="small" status={status === "" ? "normal" : status} />
};
let columns = [
    { title: "当前进度", key: "StepName", render: data => renderStep(data), width: 160, dispaly: true },
    { title: '申请人', dataIndex: 'SQR', key: 'SQR', width: 120, sorter: true, dispaly: true, filter: true, export: true },
    { title: '申请时间', key: 'CREATETIME', render: data => datetime.format(data.CREATETIME, "yyyy-MM-dd "), width: 120, sorter: true, dispaly: true, filter: true },
    { title: '审批时间', dataIndex: 'UPDATETIME', key: 'UPDATETIME', width: 180, sorter: true, dispaly: false, filter: true },
    { title: '客户名称', dataIndex: 'CUNM', key: 'CUNM', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '证件号码', dataIndex: 'IDNO', key: 'IDNO', width: 180, sorter: true, dispaly: true, filter: true },
    { title: '开户网点', dataIndex: 'UTNM', key: 'UTNM', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '开户日期', key: 'OPDT', render: data => datetime.format(data.OPDT, "yyyy-MM-dd"), width: 120, sorter: true, dispaly: true, filter: true },
    { title: '认定日期', key: 'DSDT', caption: "DSDT", render: data => datetime.format(data.DSDT, "yyyy-MM-dd"), width: 110, sorter: true, dispaly: true },
    { title: '认定说明', dataIndex: 'THSM', key: 'THSM', width: 220, sorter: true, dispaly: true, filter: true },
    { title: '营销人工号', dataIndex: 'EMNO1', key: 'EMNO1', width: 130, sorter: true, dispaly: true, filter: true },
    { title: '营销人名称', dataIndex: 'emnm1', width: 110, dispaly: true },
    { title: '占比(%)', dataIndex: 'DSVL1', key: 'DSVL1', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '管户人工号', dataIndex: 'EMNO2', key: 'EMNO2', width: 150, sorter: true, dispaly: true, filter: true, export: true },
    { title: '管户人名称', dataIndex: 'emnm2', width: 150, dispaly: true, export: true },
    { title: '管户人占比(%)', dataIndex: 'DSVL2', key: 'DSVL2', width: 150, sorter: true, dispaly: true, filter: true, export: true },
    { title: '代办人姓名1', dataIndex: 'XM1', key: 'XM1', width: 130, sorter: true, dispaly: true, filter: true, export: true },
    { title: '联系方式1', dataIndex: 'LXFS1', key: 'LXFS1', width: 130, sorter: true, dispaly: true, filter: true, export: true },
    { title: '性别1', width: 100, sorter: true, key: 'XB1', render: data => data.XB1 === "1" ? "男" : "女", dispaly: true, filter: true, export: true },
    {
        title: '亲属关系1', width: 120, sorter: true, key: 'QSGX1', render: (data) => {
            if (data.QSGX1 === "1") {
                return "父亲"
            } else if (data.QSGX1 === "2") {
                return "母亲"
            } else if (data.QSGX1 === "3") {
                return "祖父母"
            } else if (data.QSGX1 === "4") {
                return "其他"
            }
        }, dispaly: true, filter: true, export: true
    },
    {
        title: '家庭属地1', width: 150, sorter: true, key: 'SD1', render: (data) => {
            switch (data.SD1) {
                case "1": return "南京-玄武区";
                case "2": return "南京-秦淮区";
                case "3": return "南京-建邺区";
                case "4": return "南京-鼓楼区";
                case "5": return "南京-浦口区";
                case "6": return "南京-栖霞区";
                case "7": return "南京-雨花台区";
                case "8": return "南京-江宁区";
                case "9": return "南京-六合区";
                case "10": return "南京-溧水区";
                case "11": return "南京-高淳区";
                case "12": return "南京-江北新区";
                case "13": return "无锡-梁溪区";
                case "14": return "无锡-滨湖区";
                case "15": return "无锡-惠山区";
                case "16": return "无锡-锡山区";
                case "17": return "无锡-新吴区";
                case "18": return "无锡-江阴市";
                case "19": return "无锡-宜兴市";
                case "20": return "无锡-无锡经济开发区";
                case "21": return "南通-崇川区";
                case "22": return "南通-通州区";
                case "23": return "南通-海门区";
                case "24": return "南通-如东县";
                case "25": return "南通-启东市";
                case "26": return "南通-如皋市";
                case "27": return "南通-海安市";
                case "28": return "苏州-姑苏区";
                case "29": return "苏州-虎丘区";
                case "30": return "苏州-吴中区";
                case "31": return "苏州-相城区";
                case "32": return "苏州-吴江区";
                case "33": return "苏州-苏州工业园区";
                case "34": return "苏州-常熟市";
                case "35": return "苏州-张家港市";
                case "36": return "苏州-昆山市";
                case "37": return "苏州-太仓市";
            }
        }, dispaly: true, filter: true, export: true
    },
    { title: '证件号码1', dataIndex: 'ZJHM1', key: 'ZJHM1', width: 150, sorter: true, dispaly: true, filter: true, export: true },
    { title: '工作单位1', dataIndex: 'GZDW1', key: 'GZDW1', width: 180, sorter: true, dispaly: true, filter: true, export: true },
    { title: '备注1', dataIndex: 'BZ1', key: 'BZ1', width: 200, sorter: true, dispaly: true, filter: true, export: true },

    { title: '代办人姓名2', dataIndex: 'XM2', key: 'XM2', width: 150, sorter: true, dispaly: true, filter: true, export: true },
    { title: '联系方式2', dataIndex: 'LXFS2', key: 'LXFS2', width: 130, sorter: true, dispaly: true, filter: true, export: true },
    { title: '性别2', width: 100, sorter: true, key: 'XB2', render: data => data.XB2 === "1" ? "男" : data.XB2 === "2" ? "女" : "", dispaly: true, filter: true, export: true },
    {
        title: '亲属关系2', width: 120, sorter: true, key: 'QSGX2', render: (data) => {
            if (data.QSGX2 === "1") {
                return "父亲"
            } else if (data.QSGX2 === "2") {
                return "母亲"
            } else if (data.QSGX2 === "3") {
                return "祖父母"
            } else if (data.QSGX2 === "4") {
                return "其他"
            }
        }, dispaly: true, filter: true, export: true
    },
    {
        title: '家庭属地2', width: 150, sorter: true, key: 'SD2', render: (data) => {
            switch (data.SD2) {
                case "1": return "南京-玄武区";
                case "2": return "南京-秦淮区";
                case "3": return "南京-建邺区";
                case "4": return "南京-鼓楼区";
                case "5": return "南京-浦口区";
                case "6": return "南京-栖霞区";
                case "7": return "南京-雨花台区";
                case "8": return "南京-江宁区";
                case "9": return "南京-六合区";
                case "10": return "南京-溧水区";
                case "11": return "南京-高淳区";
                case "12": return "南京-江北新区";
                case "13": return "无锡-梁溪区";
                case "14": return "无锡-滨湖区";
                case "15": return "无锡-惠山区";
                case "16": return "无锡-锡山区";
                case "17": return "无锡-新吴区";
                case "18": return "无锡-江阴市";
                case "19": return "无锡-宜兴市";
                case "20": return "无锡-无锡经济开发区";
                case "21": return "南通-崇川区";
                case "22": return "南通-通州区";
                case "23": return "南通-海门区";
                case "24": return "南通-如东县";
                case "25": return "南通-启东市";
                case "26": return "南通-如皋市";
                case "27": return "南通-海安市";
                case "28": return "苏州-姑苏区";
                case "29": return "苏州-虎丘区";
                case "30": return "苏州-吴中区";
                case "31": return "苏州-相城区";
                case "32": return "苏州-吴江区";
                case "33": return "苏州-苏州工业园区";
                case "34": return "苏州-常熟市";
                case "35": return "苏州-张家港市";
                case "36": return "苏州-昆山市";
                case "37": return "苏州-太仓市";
            }
        }, dispaly: true, filter: true, export: true
    },
    { title: '证件号码2', dataIndex: 'ZJHM2', key: 'ZJHM2', width: 150, sorter: true, dispaly: true, filter: true, export: true },
    { title: '工作单位2', dataIndex: 'GZDW2', key: 'GZDW2', width: 180, sorter: true, dispaly: true, filter: true, export: true },
    { title: '备注2', dataIndex: 'BZ2', key: 'BZ2', width: 200, sorter: true, dispaly: true, filter: true, export: true },
];
const controls = [
    {
        name: "EMNO1", label: "员工1", type: "search", grid: 12 / 24, required: true,
        fetch: {
            daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'Name', valueTpl: "No"
        },
        dataType: "string", placeholder: '请输入工号或名称...'
    },
    { name: 'DSVL1', required: true, type: 'number', dataType: "number", label: '占比1(%)', min: 0, max: 100, grid: 12 / 24 },
    {
        name: "EMNO2", required: true, label: "管户人", type: "search", grid: 12 / 24,
        fetch: {
            daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'Name', valueTpl: "No"
        },
        dataType: "string", placeholder: '请输入工号或名称...'
    },
    { name: 'DSVL2', required: true, type: 'number', dataType: "number", label: '占比(%)', min: 10, max: 100, grid: 12 / 24 },
    { name: 'DSDT', type: 'date', dataType: "date", label: '变更日期', grid: 12 / 24, required: true },
    { name: 'THSM', required: true, type: 'text', label: '调户说明', dataType: "string", grid: 12 / 24 },
    { name: 'XM1', required: true, type: 'text', label: '代办人姓名1', dataType: "string", grid: 12 / 24 },
    { name: 'LXFS1', required: true, type: 'text', label: '联系方式1', dataType: "string", grid: 12 / 24 },
    { name: "XB1", label: "性别1", required: true, data: [{ value: '1', label: '男' }, { value: '2', label: '女' }], grid: 12 / 24, type: "select" },
    {
        name: "QSGX1", label: "亲属关系1", required: true,
        data: [
            { value: '1', label: '父亲' }, { value: '2', label: '母亲' }, { value: '3', label: '祖父' },
            { value: '4', label: '祖母' }, { value: '5', label: '其他' },], grid: 12 / 24, type: "select"
    },
    {
        name: "SD1", label: "家庭属地1", required: true,
        data: [
            { value: '1', label: '南京-玄武区' }, { value: '2', label: '南京-秦淮区' }, { value: '3', label: '南京-建邺区' },
            { value: '4', label: '南京-鼓楼区' }, { value: '5', label: '南京-浦口区' }, { value: '6', label: '南京-栖霞区' },
            { value: '7', label: '南京-雨花台区' }, { value: '8', label: '南京-江宁区' }, { value: '9', label: '南京-六合区' },
            { value: '10', label: '南京-溧水区' }, { value: '11', label: '南京-高淳区' }, { value: '12', label: '南京-江北新区' },
            { value: '13', label: '无锡-梁溪区' }, { value: '14', label: '无锡-滨湖区' }, { value: '15', label: '无锡-惠山区' },
            { value: '16', label: '无锡-锡山区' }, { value: '17', label: '无锡-新吴区' }, { value: '18', label: '无锡-江阴市' },
            { value: '19', label: '无锡-宜兴市' }, { value: '20', label: '无锡-无锡经济开发区' }, { value: '21', label: '南通-崇川区' },
            { value: '22', label: '南通-通州区' }, { value: '23', label: '南通-海门区' }, { value: '24', label: '南通-如东县' },
            { value: '25', label: '南通-启东市' }, { value: '26', label: '南通-如皋市' }, { value: '27', label: '南通-海安市' },
            { value: '28', label: '苏州-姑苏区' }, { value: '29', label: '苏州-虎丘区' }, { value: '30', label: '苏州-吴中区' },
            { value: '31', label: '苏州-相城区' }, { value: '32', label: '苏州-吴江区' }, { value: '33', label: '苏州-苏州工业园区' },
            { value: '34', label: '苏州-常熟市' }, { value: '35', label: '苏州-张家港市' }, { value: '36', label: '苏州-昆山市' },
            { value: '37', label: '苏州-太仓市' },
        ], grid: 12 / 24, type: "select"
    },
    { name: 'ZJHM1', required: false, type: 'text', label: '证件号码1', grid: 12 / 24 },
    { name: 'GZDW1', required: false, type: 'text', label: '工作单位1', grid: 12 / 24 },
    { name: 'BZ1', required: false, type: 'text', label: '备注1', grid: 12 / 24 },

    { name: 'XM2', required: false, type: 'text', label: '代办人姓名2', dataType: "string", grid: 12 / 24 },
    { name: 'LXFS2', required: false, type: 'text', label: '联系方式2', dataType: "string", grid: 12 / 24 },
    { name: "XB2", label: "性别2", required: false, data: [{ value: '1', label: '男' }, { value: '2', label: '女' }], grid: 12 / 24, type: "select" },
    {
        name: "QSGX2", label: "亲属关系2", required: false,
        data: [
            { value: '1', label: '父亲' }, { value: '2', label: '母亲' }, { value: '3', label: '祖父' },
            { value: '4', label: '祖母' }, { value: '5', label: '其他' },], grid: 12 / 24, type: "select"
    },
    {
        name: "SD2", label: "家庭属地2", required: false,
        data: [
            { value: '1', label: '南京-玄武区' }, { value: '2', label: '南京-秦淮区' }, { value: '3', label: '南京-建邺区' },
            { value: '4', label: '南京-鼓楼区' }, { value: '5', label: '南京-浦口区' }, { value: '6', label: '南京-栖霞区' },
            { value: '7', label: '南京-雨花台区' }, { value: '8', label: '南京-江宁区' }, { value: '9', label: '南京-六合区' },
            { value: '10', label: '南京-溧水区' }, { value: '11', label: '南京-高淳区' }, { value: '12', label: '南京-江北新区' },
            { value: '13', label: '无锡-梁溪区' }, { value: '14', label: '无锡-滨湖区' }, { value: '15', label: '无锡-惠山区' },
            { value: '16', label: '无锡-锡山区' }, { value: '17', label: '无锡-新吴区' }, { value: '18', label: '无锡-江阴市' },
            { value: '19', label: '无锡-宜兴市' }, { value: '20', label: '无锡-无锡经济开发区' }, { value: '21', label: '南通-崇川区' },
            { value: '22', label: '南通-通州区' }, { value: '23', label: '南通-海门区' }, { value: '24', label: '南通-如东县' },
            { value: '25', label: '南通-启东市' }, { value: '26', label: '南通-如皋市' }, { value: '27', label: '南通-海安市' },
            { value: '28', label: '苏州-姑苏区' }, { value: '29', label: '苏州-虎丘区' }, { value: '30', label: '苏州-吴中区' },
            { value: '31', label: '苏州-相城区' }, { value: '32', label: '苏州-吴江区' }, { value: '33', label: '苏州-苏州工业园区' },
            { value: '34', label: '苏州-常熟市' }, { value: '35', label: '苏州-张家港市' }, { value: '36', label: '苏州-昆山市' },
            { value: '37', label: '苏州-太仓市' },
        ], grid: 12 / 24, type: "select"
    },
    { name: 'ZJHM2', required: false, type: 'text', label: '证件号码2', grid: 12 / 24 },
    { name: 'GZDW2', required: false, type: 'text', label: '工作单位2', grid: 12 / 24 },
    { name: 'BZ2', required: false, type: 'text', label: '备注2', grid: 12 / 24 },

]
let controlsTable = [
    { name: 'SQR', required: true, type: 'text', label: '申请人', dataType: "string", grid: 12 / 24 },
    // { name: 'STATE', required: true, type: 'text', dataType: "string", label: '当前状态', grid: 12 / 24 },
    { name: 'IDNO', required: true, type: 'text', label: '证件号码', dataType: "string", grid: 12 / 24 },
    { name: 'CUNM', required: true, type: 'text', label: '客户名称', dataType: "string", grid: 12 / 24 },
    { name: 'UTNM', required: true, type: 'text', label: '开户网点', grid: 12 / 24 },
    { name: 'OPDT', required: true, type: 'date', label: '开户日期', dataType: "date", grid: 12 / 24 },
    { name: 'ACBL', required: true, type: 'number', label: '余额', dataType: "number", grid: 12 / 24 },
    { name: 'EMNO1', required: true, type: 'text', label: '员工1', dataType: "string", grid: 12 / 24 },
    { name: 'DSVL1', required: true, type: 'number', label: '占比1(%)', dataType: "number", grid: 12 / 24 },
    { name: 'EMNO2', required: true, type: 'text', label: '管户人', dataType: "string", grid: 12 / 24 },
    { name: 'DSVL2', required: true, type: 'number', label: '占比(%)', dataType: "number", grid: 12 / 24 },
    { name: 'DSDT', required: true, type: 'date', label: '变更日期', dataType: "date", grid: 12 / 24 },
    { name: 'THSM', required: true, type: 'text', label: '调户说明', dataType: "string", grid: 12 / 24 },
    { name: 'CREATETIME', required: true, type: 'date', label: '申请时间', dataType: "date", grid: 12 / 24 },
    { name: 'UPDATETIME', required: false, type: 'text', label: '审批时间', dataType: "string", grid: 12 / 24 },
    { name: 'XM1', required: true, type: 'text', label: '代办人姓名1', dataType: "string", grid: 12 / 24 },
    { name: 'LXFS1', required: true, type: 'text', label: '联系方式1', dataType: "string", grid: 12 / 24 },
    { name: "XB1", label: "性别1", required: true, data: [{ value: '1', label: '男' }, { value: '2', label: '女' }], grid: 12 / 24, type: "select" },
    {
        name: "QSGX1", label: "亲属关系1", required: true,
        data: [
            { value: '1', label: '父亲' }, { value: '2', label: '母亲' }, { value: '3', label: '祖父' },
            { value: '4', label: '祖母' }, { value: '5', label: '其他' },], grid: 12 / 24, type: "select"
    },
    {
        name: "SD1", label: "家庭属地1", required: true,
        data: [
            { value: '1', label: '南京-玄武区' }, { value: '2', label: '南京-秦淮区' }, { value: '3', label: '南京-建邺区' },
            { value: '4', label: '南京-鼓楼区' }, { value: '5', label: '南京-浦口区' }, { value: '6', label: '南京-栖霞区' },
            { value: '7', label: '南京-雨花台区' }, { value: '8', label: '南京-江宁区' }, { value: '9', label: '南京-六合区' },
            { value: '10', label: '南京-溧水区' }, { value: '11', label: '南京-高淳区' }, { value: '12', label: '南京-江北新区' },
            { value: '13', label: '无锡-梁溪区' }, { value: '14', label: '无锡-滨湖区' }, { value: '15', label: '无锡-惠山区' },
            { value: '16', label: '无锡-锡山区' }, { value: '17', label: '无锡-新吴区' }, { value: '18', label: '无锡-江阴市' },
            { value: '19', label: '无锡-宜兴市' }, { value: '20', label: '无锡-无锡经济开发区' }, { value: '21', label: '南通-崇川区' },
            { value: '22', label: '南通-通州区' }, { value: '23', label: '南通-海门区' }, { value: '24', label: '南通-如东县' },
            { value: '25', label: '南通-启东市' }, { value: '26', label: '南通-如皋市' }, { value: '27', label: '南通-海安市' },
            { value: '28', label: '苏州-姑苏区' }, { value: '29', label: '苏州-虎丘区' }, { value: '30', label: '苏州-吴中区' },
            { value: '31', label: '苏州-相城区' }, { value: '32', label: '苏州-吴江区' }, { value: '33', label: '苏州-苏州工业园区' },
            { value: '34', label: '苏州-常熟市' }, { value: '35', label: '苏州-张家港市' }, { value: '36', label: '苏州-昆山市' },
            { value: '37', label: '苏州-太仓市' },
        ], grid: 12 / 24, type: "select"
    },
    { name: 'ZJHM1', required: false, type: 'text', label: '证件号码1', grid: 12 / 24 },
    { name: 'GZDW1', required: false, type: 'text', label: '工作单位1', grid: 12 / 24 },
    { name: 'BZ1', required: false, type: 'text', label: '备注1', grid: 12 / 24 },

    { name: 'XM2', required: false, type: 'text', label: '代办人姓名2', dataType: "string", grid: 12 / 24 },
    { name: 'LXFS2', required: false, type: 'text', label: '联系方式2', dataType: "string", grid: 12 / 24 },
    { name: "XB2", label: "性别2", required: false, data: [{ value: '1', label: '男' }, { value: '2', label: '女' }], grid: 12 / 24, type: "select" },
    {
        name: "QSGX2", label: "亲属关系2", required: false,
        data: [
            { value: '1', label: '父亲' }, { value: '2', label: '母亲' }, { value: '3', label: '祖父' },
            { value: '4', label: '祖母' }, { value: '5', label: '其他' },], grid: 12 / 24, type: "select"
    },
    {
        name: "SD2", label: "家庭属地2", required: false,
        data: [
            { value: '1', label: '南京-玄武区' }, { value: '2', label: '南京-秦淮区' }, { value: '3', label: '南京-建邺区' },
            { value: '4', label: '南京-鼓楼区' }, { value: '5', label: '南京-浦口区' }, { value: '6', label: '南京-栖霞区' },
            { value: '7', label: '南京-雨花台区' }, { value: '8', label: '南京-江宁区' }, { value: '9', label: '南京-六合区' },
            { value: '10', label: '南京-溧水区' }, { value: '11', label: '南京-高淳区' }, { value: '12', label: '南京-江北新区' },
            { value: '13', label: '无锡-梁溪区' }, { value: '14', label: '无锡-滨湖区' }, { value: '15', label: '无锡-惠山区' },
            { value: '16', label: '无锡-锡山区' }, { value: '17', label: '无锡-新吴区' }, { value: '18', label: '无锡-江阴市' },
            { value: '19', label: '无锡-宜兴市' }, { value: '20', label: '无锡-无锡经济开发区' }, { value: '21', label: '南通-崇川区' },
            { value: '22', label: '南通-通州区' }, { value: '23', label: '南通-海门区' }, { value: '24', label: '南通-如东县' },
            { value: '25', label: '南通-启东市' }, { value: '26', label: '南通-如皋市' }, { value: '27', label: '南通-海安市' },
            { value: '28', label: '苏州-姑苏区' }, { value: '29', label: '苏州-虎丘区' }, { value: '30', label: '苏州-吴中区' },
            { value: '31', label: '苏州-相城区' }, { value: '32', label: '苏州-吴江区' }, { value: '33', label: '苏州-苏州工业园区' },
            { value: '34', label: '苏州-常熟市' }, { value: '35', label: '苏州-张家港市' }, { value: '36', label: '苏州-昆山市' },
            { value: '37', label: '苏州-太仓市' },
        ], grid: 12 / 24, type: "select"
    },
    { name: 'ZJHM2', required: false, type: 'text', label: '证件号码2', grid: 12 / 24 },
    { name: 'GZDW2', required: false, type: 'text', label: '工作单位2', grid: 12 / 24 },
    { name: 'BZ2', required: false, type: 'text', label: '备注2', grid: 12 / 24 },

];
const EditFrom = dataEditCreate(daoName);
const DataTable = dataTableCreate(daoName);
const Step = Steps.Step

class IndiClieDiviFlowXJK extends Component {
    constructor(props) {
        super(props);
        this.state = {
            dataChange: false,
            range: "doing",
            stepTitle: "",
            dataList: [],
            canEdit: false,
            isClick: false,
            isFind: false,
            display_name: 'block',
            children: true,
            childrenMsg: false
        };
    }
    componentDidMount() {
        this.props.dispatch({
            type: `${daoName}/fetchIsManager`,
            payload: { daoName }
        });
        this.loadData()
        this.loadOptionData()

    }
    loadData() {
        const seeks = [{
            WhereItems: [{
                FieldName: "#flowType",
                Operator: "=",
                FieldValues: '' + this.state.range,
            }],
            RelationSign: "AND"
        }];
        let daoName2 = daoName
        let sorter = []
        if (this.state.range === "done") {
            daoName2 = "IndiClieDiviFlowViewXJK"
            sorter = {
                field: 'CREATETIME',
                order: 'descend'
            }
        }
        if (this.state.range === "all") {
            sorter = {
                field: 'CREATETIME',
                order: 'descend'
            }
        }
        this.props.dispatch({
            type: `${daoName}/fetch`,
            payload: { daoName: daoName2, page: 1, pageSize: 20, seeks, sorter }
        });
    }
    //弹出查看历史记录的页面
    showHistoryModal() {
        if (this.state.display_name == 'none') {
            this.setState({
                display_name: 'block',
            })
        }
        else if (this.state.display_name == 'block') {
            this.setState({
                display_name: 'none',
            })
        }
        console.log(this.state.display_name)
        this.props.dispatch({
            type: `${daoName}/openImpHistory`,
            payload: {}
        });
        console.log(this.props.showImpHistory)
    }
    getChildrenMsg = (result, msg) => {
        console.log(result, msg)
        // 很奇怪这里的result就是子组件那bind的第一个参数this，msg是第二个参数
        this.setState({
            childrenMsg: msg
        })
        this.props.dispatch({
            type: `${daoName}/hideImpEd`
        });
        this.setState({
            display_name: 'block'
        })
        console.log(this.state.display_name)
        console.log(this.state.childrenMsg)
        if (this.state.childrenMsg !== showImpHistory) {
            return true;
        }
        return false;
    }
    searchData() {
        const form = this.refs.searchForm.getForm()
        form.validateFields((err, values) => {
            const idno = values.IDNO
            if (!err) {

                const seeks = [{
                    WhereItems: [{
                        FieldName: "IDNO",
                        Operator: "=",
                        FieldValues: idno,
                    }, {
                        FieldName: "ISDIVI",
                        Operator: "=",
                        FieldValues: '0',
                    }
                    ],
                    RelationSign: "AND"
                }];
                this.props.dispatch({
                    type: `IndiAccoFlow/fetch`,
                    payload: { daoName: "IndiAccoFlow", page: 1, pageSize: 10, seeks }
                });
            }
        })
    }
    loadOptionData() {
        let options = []
        controls.map(c => {
            if (c.fetch) {
                let f = c.fetch;
                if (c.type === 'cascader-select') {
                    f.isCascader = true;
                }
                if (c.type !== 'search') {
                    options.push(f);
                }
            }
        })
        if (daoName && options.length > 0) {
            this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
        }
    }
    showModelHandler(isAdd) {
        let key = null
        if (!isAdd) {
            key = this.props.selectedRowKeys[len - 1]
        }
        const len = this.props.selectedRowKeys.length;
        if (len === 0) {
            message.error('请选择要查看的数据行');
            return;
        } else {
            this.props.dispatch({
                type: `${daoName}/openEdit`,
                payload: { key }
            });
        }


    }
    /**
 * 导入
 * 下载导入模板
 */
    //===============================================
    showImportHandler() {
        this.props.dispatch({
            type: `${daoName}_DataImport/setDisplay`,
            payload: { display: true },
        });
    };
    DownTmportHandler() {
        let columnHeaders = []
        columns.map((c) => {
            const name = c.dataIndex ? c.dataIndex : c.key
            if (!name || name == "emnm1") {
                return;
            }
            if (!name || name == "emnm2") {
                return;
            }
            if (!name || name == "emnm3") {
                return;
            }
            if (!name || name == "stepName") {
                return;
            }
            let header = {
                Name: name,
                Caption: c.title,
                Width: c.width
            }
            columnHeaders.push(header)
        })
        let form = document.createElement('form');//定义一个form表单
        let whereItems = [];
        whereItems.push({
            FieldName: "ID",
            Operator: "=",
            FieldValues: "0"
        })
        const whereCauses = []
        whereCauses.push({
            WhereItems: whereItems,
            RelationSign: "AND"
        })
        const orderItems = []
        form.style = "display:none";
        form.target = "_blank";
        form.method = "post";
        form.action = `/api/ExportXlsx/${daoName}`;
        let input1 = document.createElement("input");
        input1.type = "hidden";
        input1.name = "WhereCauses";
        input1.value = JSON.stringify(whereCauses);
        let input2 = document.createElement("input");
        input2.type = "hidden";
        input2.name = "OrderItems";
        input2.value = JSON.stringify(orderItems)
        let input3 = document.createElement("input");
        input3.type = "hidden";
        input3.name = "ColumnHeaders";
        input3.value = JSON.stringify(columnHeaders);
        let input4 = document.createElement("input");
        input4.type = "hidden";
        input4.name = "PermID";
        input4.value = "" + this.props.permID;
        let input5 = document.createElement("input");
        input5.type = "hidden";
        input5.name = "UserID";
        input5.value = "" + this.props.userID;
        document.body.appendChild(form);//将表单放置在web中
        form.appendChild(input1);
        form.appendChild(input2);
        form.appendChild(input3);
        form.appendChild(input4);
        form.appendChild(input5);
        form.submit();
        document.body.removeChild(form)
    };
    //===============================================
    deleteHandler() {
        const keys = this.props.selectedRowKeys;
        const len = keys.length;
        if (len === 0) {
            message.info('请选择要删除的认定关系！', 5);
            return;
        }
        Modal.confirm({
            title: '提示',
            content: `你确认要删除选中的${len}条认定关系吗？`,
            okText: '删除',
            cancelText: '取消',
            onOk: () => {
                this.props.dispatch({
                    type: `${daoName}/remove`,
                    payload: { daoName, keys },
                });
            }
        });
    }
    edidOkHandler() {
        const form1 = this.refs.searchForm.getForm()
        const form = this.refs.diviForm.getForm()
        let IDNO
        form1.validateFields((err, values) => {
            if (!err) {
                IDNO = values.IDNO
            }
        })
        if (!IDNO) {
            return
        }
        const keys = this.props.selectedRowKeys2
        if (keys.length === 0) {
            message.info('请选择要认定的账户！', 5);
            return
        }
        form.validateFields((err, values) => {
            if (!err) {
                let t = `${daoName}/submitData`
                controls.map((c, i) => {
                    if (c.type === 'cascader-select') {
                        let vs = values[c.name];
                        if (vs.length > 0) {
                            values[c.name] = vs[vs.length - 1];
                        } else {
                            values[c.name] = null;
                        }
                    }
                    if (c.dataType === "number") {
                        values[c.name] = Number(values[c.name])
                    } else if (c.dataType === "date" || c.dataType === "datetime") {
                        const date = !values[c.name] ? null : new Date(values[c.name])
                        values[c.name] = date ? new Date(date.getFullYear(), date.getMonth(), date.getDate(), 8, 0, 0) : null
                    } else {
                        values[c.name] = values[c.name] === undefined ? null : values[c.name]
                    }
                    if (c.multiple || c.type === 'checkbox-group') {
                        values[c.name] = values[c.name].join(',');
                    }
                })
                values.UID = this.props.userID
                values.IDNO = IDNO
                const datas = keys.map(k => { return { ...values, ACID: k } })
                this.state.dataChange = true;
                this.props.dispatch({
                    type: t,
                    payload: { daoName, datas },
                })
            }
        });
    };
    hideEditHandler() {
        // const form = this.refs.diviForm.getForm();
        // form.resetFields();
        // if (this.state.dataChange) {
        //     this.props.dispatch({
        //         type: `${daoName}/reload`,
        //         payload: { daoName },
        //     });
        //     this.state.dataChange = false;
        // }
        this.props.dispatch({
            type: `${daoName}/hideEdit`
        });
    };
    //延时一秒 设置isClick为false
    enableButton() {
        const that = this
        setTimeout(function () {
            that.setState({ isClick: false })
        }, 1000);
    }
    batchSubmitHandler(bType) {
        if (this.state.isClick) {
            return
        }
        this.setState({ isClick: true })
        const keys = this.props.selectedRowKeys;
        const len = keys.length;
        if (len === 0) {
            message.info('请选择要提交的认定关系！', 5);
            this.enableButton()
            return;
        }
        const list = this.props.list
        let runIDs = []
        let isOK = true
        list.map(row => {
            if (keys.find(key => row.ID === key)) {
                if (!row.FRID) {
                    isOK = false
                }
                runIDs.push(row.FRID)
            }
        })
        if (!isOK) {
            message.info('要提交的认定关系存在校验错误，请修改！', 5);
            this.enableButton()
            return;
        }
        let ghrArr = []
        list.map(row => {
            if (keys.find(key => row.ID === key)) {
                if (Number(row.isghr) === 0) {
                    ghrArr.push(row.SQR2)
                    isOK = false
                }
            }
        })
        const ghrstr = ghrArr.join(',')
        if (!isOK) {
            message.error('要提交的认定关系管户人【' + ghrstr + '】失效，失去管户资格，请中止该流程运行。系统会次日自动中止该流程！', 10);
            this.enableButton()
            return;
        }
        bType = "agree"
        this.props.dispatch({
            type: `${daoName}/flowBatchSubmit`,
            payload: { runIDs, userID: this.props.userID, desc: "", bType },
        });

        this.cancelHandler()
        this.enableButton()
    }
    submitHandler(bType) {
        const { runID } = this.props.flowRunInfo
        bType = "agree"
        this.props.dispatch({
            type: `${daoName}/flowSubmit`,
            payload: { runID, userID: this.props.userID, desc: "", bType },
        });
        this.cancelHandler()
    }
    setExecutorHandler() {
        const { runID, currStep } = this.props.flowRunInfo
        const { checkVals } = this.state
        if (checkVals === "") {
            message.info("请您选择办理人！", 5)
        }
        this.props.dispatch({
            type: `${daoName}/setFolwExecutor`,
            payload: { runID, stepID: currStep, userIDstr: checkVals },
        });
    };
    sendBackHandler(bType) {
        const { runID, currStep } = this.props.flowRunInfo
        const { text } = this.state
        if (text === "") {
            message.info("请您填写退回意见！", 5)
            return
        }
        let bStep = 1
        let ts = "你确认要退回申请人吗"
        if (bType === "backPrev") {
            bStep = currStep - 1
            ts = "你确认要退回上一步吗"
        }
        Modal.confirm({
            title: '提示',
            content: ts,
            okText: '退回',
            cancelText: '取消',
            onOk: () => {
                this.props.dispatch({
                    type: `${daoName}/flowSendBack`,
                    payload: { runID, userID: this.props.userID, backStepID: bStep, desc: text },
                });
            }
        });
    }
    abortHandler() {
        if (this.state.isClick) {
            return
        }
        this.setState({ isClick: true })
        const keys = this.props.selectedRowKeys;
        const len = keys.length;
        if (len === 0) {
            message.info('请选择要中止的认定关系！', 5);
            this.enableButton()
            return;
        }
        const list = this.props.list
        let runIDs = []
        let isOK = true
        list.map(row => {
            if (keys.find(key => row.ID === key)) {
                if (!row.FRID) {
                    isOK = false
                }
                runIDs.push(row.FRID)
            }
        })
        Modal.confirm({
            title: '提示',
            content: `你确认要中止此流程吗？`,
            okText: '中止',
            cancelText: '取消',
            onOk: () => {
                this.props.dispatch({
                    type: `${daoName}/flowAbort`,
                    payload: { runIDs },
                });
            }
        });
        this.enableButton()
    }
    cancelHandler() {
        this.props.dispatch({
            type: `${daoName}/setFrid`,
            payload: { frid: 0 },
        });
    }
    doFlowHandler() {
        const { selectedRowKeys } = this.props
        if (selectedRowKeys.length === 0) {
            message.info("请选择要办理流程！", 5)
            return
        }
        const frid = selectedRowKeys[0]
        this.props.dispatch({
            type: `${daoName}/fetchFlowRunInfo`,
            payload: { runID: frid },
        });
    }
    rangeChangeHandler(e) {
        this.state.range = e.key
        this.loadData()
    }
    showStepHandler() {
        const len = this.props.selectedRowKeys.length;
        if (len === 0) {
            message.info('请选择要修改的认定关系！', 5);
            return;
        }
        const key = this.props.selectedRowKeys[len - 1]
        const list = this.props.list
        const index = list.findIndex(v => v.ID === key)
        const runID = list[index].FRID
        if (!runID) {
            message.info('选择的认定关系存在校验错误，请修改！', 5);
            return;
        }
        this.state.stepTitle = `${list[index].CUNM}(${list[index].IDNO})`
        this.props.dispatch({
            type: `${daoName}/fetchFlowRunInfo`,
            payload: { runID }
        });
    }
    //历史数据查看进度
    showStepHandlerhistory() {
        const len = this.props.selectedRowKeys.length;
        if (len === 0) {
            message.info('请选择要修改的认定关系！', 5);
            return;
        }
        const key = this.props.selectedRowKeys[len - 1]
        const list = this.props.list
        const index = list.findIndex(v => v.ID === key)
        const runID = list[index].FRID
        if (!runID) {
            message.info('选择的认定关系存在校验错误，请修改！', 5);
            return;
        }
        this.state.stepTitle = `${list[index].CUNM}(${list[index].IDNO})`
        this.props.dispatch({
            type: `${daoName}/fetchFlowRunInfoBak`,
            payload: { runID }
        });
    }
    hideStepHandler() {
        this.props.dispatch({
            type: `${daoName}/hideStep`,
            payload: {}
        });
    }
    onSelectChange(newList, delKeys) {
        let canEdit = false
        const oldKeys = this.props.selectedRowKeys;
        let keys = []
        oldKeys.forEach(key => {
            let isFind = false
            if (delKeys.find(key2 => key2 === key)) {
                isFind = true
            }
            if (!isFind) {
                keys.push(key)
            }
        })
        newList.forEach(row => {
            keys.push(row.ID)
        });
        const len = keys.length;
        if (len > 0) {
            const list = this.props.list
            let isOK = true
            list.map(row => {
                if (keys.find(key => row.ID === key)) {
                    if (row.step !== 1) {
                        isOK = false
                    }
                }
            })
            if (isOK) {
                canEdit = true
            }
        }

        let dataList = this.state.dataList
        newList.map(data => {
            dataList.push(data)
        })
        delKeys.map(key => {
            const index = dataList.findIndex(d => d["ID"] === key)
            dataList.splice(index, 1)
        })
        if (dataList.length <= 0) {
            this.setState({ canEdit, dataList: dataList, isFind: false })
        } else {
            if (dataList[0].step <= 3 || dataList.length > 1) {
                this.setState({ canEdit, dataList: dataList, isFind: false })
            }
            else if (dataList[0].step > 3 && dataList.length === 1) {
                this.setState({ canEdit, dataList: dataList, isFind: true })
            }
        }
    }
    renderStep() {
        const { flowRunInfo } = this.props
        const steps = flowRunInfo.stepList.map(s => {
            let desc = "未开始"
            let iszz = false
            if (flowRunInfo.state === '2' && flowRunInfo.currStep === s.id) {
                desc = "已中止"
                iszz = true
            } else if (s.state === '1') {
                desc = "办理中..."
            } else if (s.state === '2') {
                desc = "已办理"
            }
            let content = []
            s.executors.map(e => {
                let color = ""
                if (e.desc === "待办..." || e.desc === "未办") {
                    color = "gray"
                } else if (e.desc.substring(0, 2) === "中止" || e.desc === "管理员强制提交") {
                    color = "#FA541C"
                } else {
                    color = "#0D993A"
                }
                let c = <div key={e.id} ><span>{`${e.name}(${e.department})：`}</span> <br />
                    <span style={{ color: color }}>{e.desc}
                    </span>
                </div>
                content.push(c)
            })
            const descTag = <div style={{ maxHeight: "200px", overflow: "auto" }}>{content}</div>
            return <Step key={s.id} title={s.name + `【` + desc + `】`} description={descTag} />
        })
        let status = "process"
        if (flowRunInfo.state === "1") {
            status = "finish"
        } else if (flowRunInfo.state === "2") {
            status = "error"
        } else {
            const step = flowRunInfo.stepList[flowRunInfo.currStep - 1]
            if (step.appointer && step.appointer.length > 0 && step.executors.length == 0) {
                status = "wait"
            }
        }
        const current = flowRunInfo.currStep - 1
        return <Steps direction="vertical" current={current} status={status}>{steps}</Steps>
    }
    renderList() {
        let { showImpHistory, permID, showStep, showEdit, record, userID, selectedRowKeys, popedomTypes, isManager } = this.props
        const { range, canEdit, isClick } = this.state
        const pTypes = popedomTypes[permID]
        let pt = false
        if (pTypes.indexOf('Y') !== -1) {
            pt = true
        }
        const attachP = {
            UID: '' + userID
        }
        const menu = <Menu onClick={this.rangeChangeHandler.bind(this)}>
            <Menu.Item key="doing">在办</Menu.Item>
            <Menu.Item key="done">已办</Menu.Item>
            {isManager ? <Menu.Item key="manager">管理</Menu.Item> : null}
            <Menu.Item key="all">全部</Menu.Item>
        </Menu>
        const butts = <ButtonGroup style={{ zIndex: 0, display: this.state.display_name }}>
            <Dropdown overlay={menu} trigger={['click']}>
                <Button type="ghost" style={{ margin: 5 }}>
                    {range === "doing" ? "在办" : range === "done" ? "已办" : range === "manager" ? "管理" : "全部"}<Icon type="down" />
                </Button>
            </Dropdown>
            {range === "doing" || range === "done" || range === "manager" || range === "all" ? <Button onClick={this.showStepHandler.bind(this)}>查看进度</Button> : null}
            {range === "doing" || range === "manager" ? <Button onClick={this.batchSubmitHandler.bind(this)} disabled={isClick}>提交</Button> : null}
            {range === "doing" && selectedRowKeys.length > 0 && !canEdit || range === "manager" ? <Button onClick={this.abortHandler.bind(this)} disabled={isClick}>中止</Button> : null}
        </ButtonGroup>
        const controls2 = [
            { name: 'IDNO', required: true, type: 'text', label: '证件号码', dataType: "string", grid: 12 / 24, layout: { labelSpan: 8, wrapperSpan: 16 } },
            { name: 'BT', required: false, type: 'button-group', data: [{ value: '1', label: '搜索', onClick: this.searchData.bind(this) }], grid: 4 / 24 },
        ]
        let datalist = this.state.dataList === undefined ? [] : this.state.dataList
        let idnos = []
        if (datalist.length > 0) {
            datalist.map(data => {
                idnos.push(data.IDNO)
            })
        }
        let idno = idnos.join(",")

        if (range === "done" || range === "all" || range === "manager") {
            columns[3].dispaly = true
        } else {
            columns[3].dispaly = false
        }

        return (
            <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
                <div>
                    <div className={styles.create}>
                        {butts}
                    </div>
                    {showImpHistory ? <div></div> : <div>
                        <DataTable ref="diviTable" daoName={daoName} columns={columns} controls={controlsTable} permID={permID} onSelectChange={this.onSelectChange.bind(this)} multiSelect={true} />
                    </div>}

                    {showStep ? <Modal title={this.state.stepTitle} width={400} visible={showStep} onCancel={this.hideStepHandler.bind(this)}
                        footer={null}
                    >
                        {this.renderStep()}
                    </Modal> : null}
                </div>
            </div>
        )
    }
    render() {
        return this.renderList()
    }
}

function mapStateToProps(state) {
    const { showImpHistory, showEdit, showStep, record, list, selectedRowKeys, keyName, flowRunInfo, frid, isManager } = state[daoName];
    const { record: record2, list: list2, selectedRowKeys: selectedRowKeys2 } = state["IndiAccoFlow"];
    const { userID, orgID, pOrgID, popedomTypes } = state.menus;
    return {
        loading: state.loading.models[daoName],
        userID,
        orgID,
        pOrgID,
        popedomTypes,
        list,
        showEdit,
        showStep,
        selectedRowKeys,
        keyName,
        record,
        flowRunInfo,
        frid,
        selectedRowKeys2,
        list2,
        record2,
        isManager,
        showImpHistory,
    }
}
IndiClieDiviFlowXJK = connect(mapStateToProps)(IndiClieDiviFlowXJK)
export default IndiClieDiviFlowXJK;
let render = (props) => React.createElement(IndiClieDiviFlowXJK, props);
let f = new Factory()
f.set("IndiClieDiviFlowXJK", render)
